package com.epoint.mobileoa.personalized.epointcompany.ui.kaoqing;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.epoint.mobileoa.bizlogic.FrameParam;

public class GPSHelper {

	public boolean isGet;
	private KaoQingView kaoQingView;
	public LocationClient mLocationClient = null;

	public GPSHelper(Context context) {
		isGet = false;
		kaoQingView = (KaoQingView) context;
		mLocationClient = ((FrameParam) kaoQingView.getApplication()).mLocationClient;
		((FrameParam) kaoQingView.getApplication()).setGPSHandler(kaoQingView);
		setLocationOption();
		mLocationClient.registerLocationListener(((FrameParam) kaoQingView
				.getApplication()).myListener);
	}

	public void getLocation() {
		Log.i("tracy", "getLocation");
		stop();
		// try {
		((FrameParam) kaoQingView.getApplication()).isGet = false;
		mLocationClient.start();
		// } catch (Exception e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
	}

	// public GPSInfo getGPS() {
	// return gpsInfo;
	// }

	public void stop() {
		if (mLocationClient.isStarted()) {
			mLocationClient.stop();
		}
	}

	// 设置相关参数
	private void setLocationOption() {
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true); // 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型
		option.setPoiNumber(1);
		option.setPoiExtraInfo(true);
		option.setPoiDistance(100);
		option.setScanSpan(2000);// 设置定位模式，小于1秒则一次定位;大于等于1秒则定时定位
		option.setPriority(LocationClientOption.GpsFirst);
		mLocationClient.setLocOption(option);
	}

	public interface GPSCallBack {
		void onBack(GPSInfo gpsInfo);
	}
}
